package leetcode.code;

import java.util.Arrays;

public class Solution453 {

	public int minMoves(int[] nums) {
		int min = Arrays.stream(nums).min().getAsInt();
		int sum = Arrays.stream(nums).sum();
		int n = nums.length;
		return sum - n * min;
	}

	public int minMoves2(int[] nums) {
		int min = nums[0];
		int n = nums.length;
		int sum = 0;
		for (int num : nums) {
			sum += num;
			min = Math.min(min, num);
		}
		return sum - n * min;
	}

	public int minMoves1(int[] nums) {
		int min = nums[0];
		int n = nums.length;
		int sum = nums[0];
		for (int i = 1; i < n; i++) {
			int num = nums[i];
			sum += num;
			min = Math.min(min, num);
		}
		return sum - n * min;
	}
}
